<?php

	require_once "../PinSQL.obj" ;
	$pinSQL = new PinSQL();
	
	$type = $_POST['type'];
	$site_root = "../../";
	require_once "Gallery_new.obj";
	include "setupGallery.php"; //creates a $gallery object which we can use for table names and other specifics

	// deal with the comments
	$itemID = $_POST["itemid"];

    // read contents of table into $result variable
    $pinSQL->Query("SELECT * FROM $gallery->dataTable WHERE id='$itemID'");
    
    $row = $pinSQL->FetchNextRow();

    $name = $row["name"];
	$artist = $row["artist"];
	$filename = $row["filename"];
	$totalstars = $row["totalstars"];
	$totalratings = $row["totalratings"];
	   
	// find out if the media has any comments
	$result2 = mysql_query("SELECT * FROM $gallery->commentsTable WHERE itemid='$itemID'") or die(mysql_error());

	// get number of rows that $result2 returned, into $num2
	$numcomments = 0;
	$numcomments = mysql_numrows($result2);
	
?>
     
<?php
	echo $name . "\n";
	
	$gallery->SetCurrentItem($itemID);
	$gallery->OutputListItemFill();
?>
	     <div id="row">
	     	<div class="medialist_stars">
	        	<?php 
	        		// show appropriate number of stars
					if ($totalratings > 0) // this is so it doesn't divide by zero if there are no ratings
					{
						$averagestars = round($totalstars / $totalratings / 2, 0);
						echo "<img src=\"img/gauge_$averagestars.png\" />";
					} else {
					   // the song has not been rated
					}
					
	                 ?>
			</div>
			<div class="medialist_item_info">
				<span id="<?php echo "leftarea$i"; ?>">
					<?php if ($totalratings != 0) echo $totalratings . ' ratings'; ?>
				</span>
					<?php if ($totalratings != 0 && $numcomments != 0) echo ' | '; ?>
					<?php if ($numcomments != 0) echo $numcomments . ' comments'; ?>
			</div>
			<div style="clear: both;"></div>
			
		</div>

<?php
     
	mysql_close();

?>